import sys

reload(sys)
sys.setdefaultencoding('utf-8')
from jinja2 import Template

template_filename = '/Users/hiking/AutoPackage/template_test/test.tpl'


def mytest():
    try:
        with open(template_filename, 'r') as f:
            node_doc_template = Template(f.read().decode('utf-8'))
            f.close()
    except Exception as e:
        print '[ERROR] Parse tpl file fal: %s' % e
        return

    module_list = {}
    res = node_doc_template.render(
        DATA=module_list,
        seq=[{'type': 'str', 'subtype': '1111111'}, {'type': 'list', 'subtype': 'str'}]
    )

    with open('test2.txt', 'w+') as f:
        f.write(res.encode('utf-8'))
        f.close()

    return res


if __name__ == '__main__':
    mytest()
